//Ta Duc Viet
//Tinh trung binh va do lech chuan
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
void test_1_value( float a[]); 
void test_2_value( float a[]);
void test_3_value( float a[]);
void test_4_value( float a[]);
float average( float a[], int n);
float standard_deviation (float a[], int n);
int main(){
	int n;
	cout << "This program tests my two new functions." << endl;
	do {
		cout << "Do you wish to test 1, 2, 3 or 4 numbers (enter 0 to end the program):";
		cin >> n;
		float a[4] = { 0 };
		if ( n > 4 || n < 0){
			cout << "Sorry, the program can only test 1, 2, 3 or 4 values." << endl;
			continue;
			}
		switch (n){
		case 1:
			test_1_value(a);
			cout << "Average: " << average( a, n);
			cout << " Standard deviation:" << standard_deviation( a, n) << endl;
			break;
		case 2:
			test_2_value(a);
			cout << "Average: " << average( a, n);
			cout << " Standard deviation:" << standard_deviation( a, n) << endl;
			break;
		case 3:
			test_3_value( a);
			cout << "Average: " << average( a, n);
			cout << " Standard deviation:" << standard_deviation( a, n) << endl;
			break;
		case 4:
			test_4_value( a);
			cout << "Average: " << average( a, n);
			cout << " Standard deviation:" << standard_deviation( a, n) << endl;
			break;
		}
		}
		while ( n != 0); 
	cout << "Finished testing." << endl;
	system ("pause");
	return 0;
}
void test_1_value( float a[]){
	cout << "Enter first value:";
	cin >> a[0];
}
void test_2_value( float a[]){
	cout << "Enter first value:";
	cin >> a[0];
	cout << "Enter second value:";
	cin >> a[1];
}
void test_3_value( float a[]){
	cout << "Enter first value:";
	cin >> a[0];
	cout << "Enter second value:";
	cin >> a[1];
	cout << "Enter third value:";
	cin >> a[2];
}
void test_4_value( float a[]){
	cout << "Enter first value:";
	cin >> a[0];
	cout << "Enter second value:";
	cin >> a[1];
	cout << "Enter third value:";
	cin >> a[2];
	cout << "Enter fourth value";
	cin >> a[3];
}
float average( float a[], int n){
	return ( a[0] + a[1] + a[2] + a[3]) / n;
}
float standard_deviation (float a[], int n){
	float ave, sum;
	sum = 0;
	ave = average(a, n);
	for ( int i = 0; i < n; i++){
		sum = sum + pow (a[i] - ave,2);
	}
	return sqrt( sum / n);
}
